package net.flyinggroup.scalar;

import net.flyinggroup.scalar.model.Product;
import net.flyinggroup.scalar.repository.ProductRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@SpringBootApplication
public class ScalarApplication {
    public static void main(String[] args) {
        SpringApplication.run(ScalarApplication.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner(ProductRepository repository) {
        return args -> {
            List<Product> products = List.of(new Product("Product 1", true, 0.9f, 5, new BigDecimal("9.99"), LocalDateTime.now()),
                    new Product("Product 2", false, 0.8f, 6, new BigDecimal(9.99), LocalDateTime.now()),
                    new Product("Product 3", true, 0.99f, 78, new BigDecimal("9.99"), LocalDateTime.now()));
            repository.saveAll(products);
            repository.findAll().forEach(System.out::println);
        };
    }
}
